﻿using AutoMapper;
using JESAI.AutoMapper.Extensions;
using System;
using System.Collections.Generic;
using System.Text;

namespace JESAI.AutoMapper.Attributes
{
    public class AutoMapFromAttribute : AutoMapAttributeBase
    {
        public MemberList MemberList { get; set; } = MemberList.Destination;
        public AutoMapFromAttribute(params Type[] targetTypes):base(targetTypes)
        {

        }
        public AutoMapFromAttribute(MemberList memberList, params Type[] targetTypes) : base(targetTypes)
        {
            MemberList = MemberList;
        }
        public override void CreateMap(IMapperConfigurationExpression configuration, Type type)
        {
            if (TargetTypes.IsNullOrEmpty())
            {
                return;
            }

            foreach (var targetType in TargetTypes)
            {
                configuration.CreateAutoAttributeMaps(targetType, new[] { type }, MemberList);
            }
        }
    }
}
